#include "stdafx.h"

#include <Money.h>
#include <Bank.h>
#include <Sum.h>


namespace
{
	TEST( Money, SimpleAddition )
	{
		const auto five( Money::Dollar( 5 ) );
		const auto sum( *five + *five );
		const Bank cBank;
		const auto reduced( cBank.Reduce( *sum, _T("USD") ) );
		EXPECT_EQ( *Money::Dollar( 10 ), *reduced );
	}

	TEST( Money, PlusReturnsSum )
	{
		const auto fiveBucks( Money::Dollar( 5 ) );
		const auto tenFrancs( Money::Franc( 10 ) );
		const auto result( *fiveBucks + *tenFrancs );
		const auto sum( std::dynamic_pointer_cast<Sum>( result ) );
		ASSERT_TRUE( sum );
		EXPECT_EQ( *fiveBucks, *sum->m_spAugend );
		EXPECT_EQ( *tenFrancs, *sum->m_spAddend );
	}

	TEST( Money, MixedAddition )
	{
		const ExpressionSp fiveBucks( Money::Dollar( 5 ) );
		const ExpressionSp tenFrancs( Money::Franc( 10 ) );
		Bank bank;
		bank.AddRate( _T("CHF"), _T("USD"), 2 );
		const auto result( bank.Reduce( *(*fiveBucks + *tenFrancs), _T("USD") ) );
		EXPECT_EQ( *Money::Dollar( 10 ), *result );
	}

} // unnamed namespace
